﻿namespace HRM.CORE
{
    using DevExpress.XtraEditors;
    using HRM.CORE.Workdesk;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;

    public class xfmDiagram : XtraForm
    {
        private IContainer components;
        private HRM.CORE.Workdesk.xucDiagram xucDiagram;

        public event ItemClickedEventHander ItemClicked;

        public xfmDiagram()
        {
            this.components = null;
            this.InitializeComponent();
            this.Init();
        }

        public xfmDiagram(int Type)
        {
            this.components = null;
            this.InitializeComponent();
            this.Init(Type);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Init()
        {
            this.xucDiagram = new HRM.CORE.Workdesk.xucDiagram();
            this.xucDiagram.Dock = DockStyle.Fill;
            this.xucDiagram.ItemClicked += (s, i) => this.RaiseItemClickedHander(i);
            base.Controls.Add(this.xucDiagram);
        }

        private void Init(int Type)
        {
            this.xucDiagram = new HRM.CORE.Workdesk.xucDiagram(Type);
            this.xucDiagram.Dock = DockStyle.Fill;
            this.xucDiagram.ItemClicked += (s, i) => this.RaiseItemClickedHander(i);
            base.Controls.Add(this.xucDiagram);
        }

        private void InitializeComponent()
        {
            base.SuspendLayout();
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x2e0, 0x1f5);
            base.Name = "xfmDiagram";
            this.Text = "Sơ Đồ Chức Năng";
            base.ResumeLayout(false);
        }

        public void LoadContentHtml(string Html)
        {
            if (this.xucDiagram != null)
            {
                this.xucDiagram.LoadContentHtml(Html);
            }
        }

        public void LoadInterface(int Type)
        {
            if (this.xucDiagram != null)
            {
                this.xucDiagram.LoadInterface(Type);
            }
        }

        private void RaiseItemClickedHander(string Item)
        {
            if (this.ItemClicked != null)
            {
                this.ItemClicked(this, Item);
            }
        }

        public void SetStyle(string Style)
        {
            if (this.xucDiagram != null)
            {
                this.xucDiagram.SetStyle(Style);
            }
        }

        public delegate void ItemClickedEventHander(object sender, string Item);
    }
}

